<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="-1">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="Generator" content="">
<link rel="icon" type="image/x-icon" href="">
<link rel="stylesheet" type="text/css" href="../rebot/log.css" media="all">
<link rel="stylesheet" type="text/css" href="../rebot/common.css" media="all">
<link rel="stylesheet" type="text/css" href="../rebot/print.css" media="print">
<link rel="stylesheet" type="text/css" href="../common/doc_formatting.css" media="all">
<link rel="stylesheet" type="text/css" href="../common/js_disabled.css" media="all">
<script type="text/javascript" src="../lib/jquery.min.js"></script>
<script type="text/javascript" src="../lib/jquery.tmpl.min.js"></script>
<script type="text/javascript" src="../rebot/util.js"></script>
<style type="text/css" media="all">
#header {
  height: 4em;
  width: auto;
}
</style>
<!-- JS MODEL --><script type="text/javascript" src="../testdata/testdoc.js"></script>
<title></title>
</head>
<body>
<div id="javascript_disabled">
  <h1>Opening test suite documentation failed</h1>
  <ul>
    <li>Verify that you have <b>JavaScript enabled</b> in your browser.</li>
    <li>Make sure you are using a <b>modern enough browser</b>. Firefox 3.5, IE 8, or equivalent is required, newer browsers are recommended.</li>
    <li>Check are there messages in your browser's <b>JavaScript error log</b>. Please report the problem if you suspect you have encountered a bug.</li>
  </ul>
</div>
<script type="text/javascript">
    // Not using jQuery here for maximum speed
    document.getElementById('javascript_disabled').style.display = 'none';
</script>

<div id="header"><h1></h1></div>

<script type="text/javascript">
$(document).ready(function(){
    parseTemplates();
    addTitle(window.testdoc.title);
    addGenerated(window.testdoc.generated, window.testdoc.generatedMillis);
    addSuite(window.testdoc.suite, 'body');
    expandElement(window.testdoc.suite.id);
});

function parseTemplates() {
    $('script[type="text/x-jquery-tmpl"]').map(function (idx, elem) {
        $.template(elem.id, elem.text);
    });
}

function addTitle(title) {
    document.title = title;
    $('h1').text(title);
}

function addGenerated(timestamp, millis) {
    $.tmpl('<div id="generated">' +
             '<span>Generated<br>${generated}</span><br>' +
             '<span id="generated_ago">${generatedAgo} ago</span>' +
           '</div>', {
        generated: timestamp,
        generatedAgo: util.createGeneratedAgoString(millis)
    }).appendTo($('#header'));
}

function addSuite(suite, parent_locator) {
    $.tmpl('suiteTemplate', suite).appendTo($(parent_locator));
    addKeywords(suite);
    addSuites(suite);
    addTests(suite);
}

function addSuites(suite) {
    $.map(suite.suites, function (s, _) {
        addSuite(s, '#' + suite.id + '_children');
    });
}

function addTests(suite) {
    $.map(suite.tests, function (test, _) {
        $.tmpl('testTemplate', test).appendTo($('#' + suite.id + '_children'));
        addKeywords(test);
    });
}

function addKeywords(parent) {
    $.map(parent.keywords, function (kw, _) {
        $.tmpl('keywordTemplate', kw).appendTo($('#' + parent.id + '_children'));
    });
}

function toggleElement(elementId) {
    var childElement = $("#"+elementId+"_children");
    childElement.toggle(100, function () {
        var foldingButton = $('#'+elementId+'_foldingbutton');
        foldingButton.text(foldingButton.text() == '+' ? '-' : '+');
    });
}

function expandElement(elementId) {
    var childElement = $("#" + elementId + "_children");
    childElement.show();
    $('#'+elementId+'_foldingbutton').text('-');
    return childElement;
}

function expandAllChildren(elementId) {
    var elem = expandElement(elementId);
    var childrenToClick = elem.find('[class="expandall"]');
    for (var i = 0; i < childrenToClick.length; i++) {
        childrenToClick[i].click();
    }
}

// For complete cross-browser experience..
// http://www.quirksmode.org/js/events_order.html
function stopPropagation(event) {
    var event = event || window.event;
    event.cancelBubble = true;
    if (event.stopPropagation)
        event.stopPropagation();
}
</script>

<script type="text/x-jquery-tmpl" id="suiteTemplate">
  <div id="${id}" class="suite">
    <div id="${id}_elementheader" class="elementheader"
         onclick="toggleElement('${id}');" title="${fullName}">
      <div id="${id}_foldingbutton" class="foldingbutton">+</div>
      <span class="not_run">TEST&nbsp;SUITE:</span>
      <span class="name">${name}</span>
        <a class="expandall" href="javascript:expandAllChildren('${id}')"
           onclick="stopPropagation(event);">Expand All</a>
    </div>
    <div id="${id}_children" style="display: none;">
      <table class="metadata">
        <tr>
          <th>Full Name:</th>
          <td>${fullName}</td>
        </tr>
        {{if doc}}
        <tr>
          <th>Documentation:</th>
          <td class="doc">{{html doc}}</td>
        </tr>
        {{/if}}
        {{each metadata}}
        <tr>
          <th>${$value[0]}:</th>
          <td class="doc">{{html $value[1]}}</td>
        </tr>
        {{/each}}
        {{if source}}
        <tr>
          <th>Source:</th>
          {{if relativeSource}}
          <td><a href="${relativeSource}">${source}</a></td>
          {{else}}
          <td>${source}</td>
          {{/if}}
        </tr>
        {{/if}}
        <tr>
          <th>Number of Tests:</th>
          <td>${numberOfTests}</td>
        </tr>
      </table>
    </div>
  </div>
</script>

<script type="text/x-jquery-tmpl" id="testTemplate">
  <div id="${id}" class="test">
    <div id="${id}_elementheader" onclick="toggleElement('${id}');"
         class="elementheader" title="${fullName}">
      <div id="${id}_foldingbutton" class="foldingbutton">+</div>
      <span class="not_run">TEST&nbsp;CASE: </span>
      <span class="name">${name}</span>
        <a class="expandall" href="javascript:expandAllChildren('${id}')"
           onclick="stopPropagation(event);">Expand All</a>
    </div>
    <div id="${id}_children" style="display: none;">
      <table class="metadata">
        <tr>
          <th>Full Name:</th>
          <td>${fullName}</td>
        </tr>
        {{if doc}}
        <tr>
          <th>Documentation:</th>
          <td class="doc">{{html doc}}</td>
        </tr>
        {{/if}}
        {{if tags.length}}
        <tr>
          <th>Tags:</th>
          <td>${tags.join(', ')}</td>
        </tr>
        {{/if}}
        {{if timeout}}
        <tr>
          <th>Timeout:</th>
          <td>${timeout}</td>
        </tr>
        {{/if}}
      </table>
    </div>
  </div>
</script>

<script type="text/x-jquery-tmpl" id="keywordTemplate">
  <div class="elementheader" style="cursor: auto;">
    <div class="keyword">
      <span class="not_run">${type}: </span>
      <span class="name">${name}</span>
      <span class="arg">${arguments}</span>
    </div>
  </div>
</script>

</body>
</html>
